package br.com.iswe.gwt.util.client;

import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.MouseListenerAdapter;
import com.google.gwt.user.client.ui.Widget;

public class ToolTipMouseListener extends MouseListenerAdapter {
	
	boolean showTip = false;
	private String tipText = "";
	
	public ToolTipMouseListener(String tipText){
		this.tipText = tipText;
	}
	
	public void onMouseMove(Widget sender, int x, int y) {
		if (showTip) {
			y = y + DOM.getAbsoluteTop(sender.getElement()) - 30;
			x = x + DOM.getAbsoluteLeft(sender.getElement()) - 50;
			ClientUtils.showTip(tipText, x, y);
		}
	}
	
	public void onMouseDown(Widget sender, int x, int y) {
		ClientUtils.hideTip();
	}

	public void onMouseEnter(Widget sender) {
		showTip = true;
	}

	public void onMouseLeave(Widget sender) {
		showTip = false;
		ClientUtils.hideTip();
	}
}
